package com.interfaz.tabla.jcb;

import java.awt.Component;
import java.util.Vector;

import javax.swing.DefaultCellEditor;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JTable;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.controlador.ModeloController;
import com.help.ModeloRenderer;
import com.modelo.Marca;
import com.modelo.Modelo;

public class JCModeloCellEditor extends DefaultCellEditor {
	private DefaultComboBoxModel model;
	private Modelo modelo = null;
	private ModeloController modelo_controller;
	private Vector<Modelo> vector_modelo;
	JComboBox jcbModelo = new JComboBox();

	public JCModeloCellEditor() {
		super(new JComboBox());
		
		this.model = (DefaultComboBoxModel)((JComboBox)getComponent()).getModel();
		
		// TODO Auto-generated constructor stub
	}
	
//	private void configureRenderer(ModeloRenderer renderer, Object value) {
//	    Modelo m = (Modelo)value;
//		renderer.setText(m.getNombre());
//	  }
	
	public Component getTableCellEditorComponent(JTable tabla, Object value, boolean isSelected, int row, int column){
		System.out.println("LLego al metodo: JCModeloCellEditor: getTableCellEditorComponent()");
		modelo_controller = new ClassPathXmlApplicationContext("applicationContext.xml").getBean("modeloService",ModeloController.class);
		vector_modelo = new Vector<Modelo>();
		vector_modelo = null;
		model.removeAllElements();
		//System.out.println("JCMOdeloCellEditor getTableCellEditorComponent() "+value.toString());
		System.out.println("JCMOdeloCellEditor getTableCellEditorComponent() "+value);
		//Marca marca_seleccionada = (Marca)tabla.getValueAt(row,3);
		String marca_seleccionada = (String)tabla.getValueAt(row,3);
		for(Modelo m_x_l : modelo_controller.buscarModelosElementoNuevo(1)){
			System.out.println("JCModeloCellEditor: "+m_x_l.getNombre());
			vector_modelo.add(m_x_l);  
		}
		model.addElement(vector_modelo);
		return super.getTableCellEditorComponent(tabla, value, isSelected, row, column);
	}
}
